// *************************************
// DEEP - EFMP Fleet analysis
// EFMP_TripleDiff_nn.do
// *************************************

/*
// Description
// ----------------------------
This program analyses the Enhanced Fleet Modernization Program (EFMP) in 
California.  It performs a triple difference (TD) analysis on merged Experian 
fuel efficiency moments. 
*/

/*** START CODE ***/

// Preamble
// ----------------------------
capture log close
clear all
version 14.2
set more off
set matsize 800


use "${EFMPFleetData}/PreNN_forMerge.dta", clear
	

** Merge Nearest Neighbour Data from EFMP_NNMatch*.do and drop unmatched zips
merge m:1 zip using "${EFMPFleetData}/NNData_fullAQMDmatch.dta"
drop _merge
compress
drop __000000
ren zip zip_label 
merge m:1 zip_label using "${MapFiles}/zip_codes_in_scaqmd.dta", keep(1 3)
drop _merge
replace scaqmd_dum = 0 if scaqmd_dum == . 
ren zip_label zip


foreach x of varlist frac_efmp_pu* avgsubsidy_total* avgsubsidy_efmp_pu* avgsubsidy_efmp_base* {
	replace `x' = 0 if _fillin == 1
}

foreach x in CalendarYear Quarter {
bys runquarter: egen temp_`x' = max(`x')
replace `x' = temp_`x' if _fillin == 1
drop temp_`x'
}

foreach x of varlist aqmd dac PL225_frac PL300_frac PL400_frac MaxCES nn_*  { 
local tempvar maxval
bys zip: egen tempvar = max(`x')
replace `x' = tempvar if _fillin == 1
drop tempvar
}

gen yq = yq(CalendarYear, Quarter)
format yq %tq


/*Generate scaled avg subsidy variable in $000*/
foreach x of varlist avgsubsidy* {
gen scl_`x' = `x'/1000
}

foreach var of varlist frac_efmp_pu* {
	gen scl_`var' = `var'*100 
}
drop if zip==.

save "${EFMPFleetData}/NN_TripDiffPreTrendGraphData.dta", replace 

//Construct IVs

do "${EFMPFleetCode}/EFMP_ConstructIVMatch.do"

use "${EFMPFleetData}/NN_TripDiffPreTrendGraphData.dta", clear 


merge 1:1 zip runquarter using "${EFMPFleetData}/NN_IVConstruct.dta"
drop _merge


save "${EFMPFleetData}/NN_RegData.dta", replace 
	

/**************************************************/
/*REGRESSIONS SPECIFICATIONS                      */
/**************************************************/	


use "${EFMPFleetData}/NN_RegData.dta", clear 

/*Variable Labels*/
global outvarGlobal "gpm"
global outputSubfolder "BootstrapResults"

label var scl_frac_efmp_pu "\% point EFMP Transactions"
label var scl_avgsubsidy_efmp_pu "Avg. PU Subsidy (thousand USD)"
label var scl_avgsubsidy_efmp_pu "Avg. PU Subsidy"

foreach vtype in BEV HEV ICE PHEV {
label var scl_frac_efmp_pu`vtype' "\% point EFMP `vtype' Transactions"
label var scl_avgsubsidy_efmp_pu`vtype' "Avg. PU `vtype' Subsidy (thousand USD)"
label var scl_avgsubsidy_efmp_pu`vtype' "Avg. PU `vtype' Subsidy"

}

local absorb1 "i.zip i.dac##i.runquarter i.aqmd##i.runquarter" 
local absorb2 "i.zip i.dac##i.runquarter i.sj_dum##i.runquarter i.sc_dum##i.runquarter" 
local ctrls "" 

*local macros for zip weights for matched specifications
local outcomeMatch nn_gpm_pretrend_freq
local QMatch nn_Q_pretrend_freq

local outcomevar ${outvarGlobal}

estimates clear	
set more off

// summary GPMs that we estimated from data matched with fueleconomy.gov

	local gpmEFMP 	= .0230758
	local gpmBEV 	= .0092646
	local gpmHEV 	= .0269494
	local gpmPHEV 	= .0248565 
	local vtypes "BEV PHEV HEV"


***************
***Program to capture CIs for Bootstraps
**Run program with "CIs"
**Saves estimates "(XX.X,YY.Y)"

capture program drop CIs
program define CIs, rclass
	version 14.0
	matrix se_boot = e(ci_bc)
	local CIL = el(se_boot,1,1)
	local CIH = el(se_boot,2,1)
	
	local se = "(" + string(el(se_boot,1,1), "%10.1fc") + "," + string(el(se_boot,2,1), "%10.1fc") + ")"
	
	*return scalar cil = `CIL'
	*return scalar cih = `CIH'
	return local se = "`se'"
	local CI = "(" + string(`CIL', "%10.3fc") + ")" 
	display `CI'
end



*****************
/*OLS SPECIFICATIONS*/	

/*UNMATCHED AND MATCHED OLS DIFF-IN-DIFF ON DAC==1, AVG FUEL ECONOMY*/
	
	reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu if dac==1, ///
		absorb(`absorb1') vce(cluster zip)
	local coef1 = 1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )
	estadd scalar MR = `coef1', replace
	estimates store DinD_`outcomevar'_frac
		*Bootstrap of MR
		bootstrap mpg_boot1 = (1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )), reps(250) seed(123) : reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu if dac==1, absorb(`absorb1') vce(cluster zip)
		
		CIs
		estadd local ci = r(se) : DinD_`outcomevar'_frac
	*
	reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu [fw=`outcomeMatch'] if dac==1, ///
		absorb(`absorb1') vce(cluster zip) 
	local coef1 = 1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )
	estadd scalar MR = `coef1', replace
	estimates store DinD_match_`outcomevar'_frac
		*Bootstrap of MR
		bootstrap mpg_boot2 = (1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )), reps(250) seed(123) force : reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu [fw=`outcomeMatch'] if dac==1, absorb(`absorb1') vce(cluster zip) 
		CIs
		estadd local ci = r(se) : DinD_match_`outcomevar'_frac
	*
	reghdfe `outcomevar' `ctrls' scl_avgsubsidy_efmp_pu if dac==1, ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store DinD_`outcomevar'_avgsub
	*
	reghdfe `outcomevar' `ctrls' scl_avgsubsidy_efmp_pu [fw=`outcomeMatch'] if dac==1, ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store DinD_match_`outcomevar'_avgsub

	
/*UNMATCHED AND MATCHED OLS TRIPLEDIFF, AVG FUEL ECONOMY*/
	
	****
	reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu, ///
		absorb(`absorb1') vce(cluster zip) 
	local coef1 = 1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )
	estadd scalar MR = `coef1', replace
	estimates store DDD_`outcomevar'_frac
		*Bootstrap of MR
		bootstrap mpg_boot3 = (1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )), reps(250) seed(123) : reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu, absorb(`absorb1') vce(cluster zip) 
		CIs
		estadd local ci = r(se) : DDD_`outcomevar'_frac
	*****
	reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu [fw=`outcomeMatch'], ///
		absorb(`absorb1') vce(cluster zip) 
	local coef1 = 1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )
	estadd scalar MR = `coef1', replace
	estimates store DDD_match_`outcomevar'_frac
		*Bootstrap of MR
		bootstrap mpg_boot4 = (1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )), reps(250) seed(123) force: reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu [fw=`outcomeMatch'], absorb(`absorb1') vce(cluster zip) 
		CIs
		estadd local ci = r(se) : DDD_match_`outcomevar'_frac	
	****
	reghdfe `outcomevar' `ctrls' scl_avgsubsidy_efmp_pu, ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store DDD_`outcomevar'_avgsub

	reghdfe `outcomevar' `ctrls' scl_avgsubsidy_efmp_pu [fw=`outcomeMatch'], ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store DDD_match_`outcomevar'_avgsub

	
	
/*IDENTIFICATION FROM WITHIN ZIP VARIATION IN TREATMENT INTENSITY, DAC == 1, AQMD == 1, AVG FUEL ECONOMY*/
	
	reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu if dac==1 & aqmd==1, ///
		absorb(`absorb1') vce(cluster zip)
	local coef1 = 1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )
	estadd scalar MR = `coef1', replace
	estimates store withinzip_`outcomevar'_frac
		*Bootstrap of MR
		bootstrap mpg_boot5 = (1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )), reps(250) seed(123) : reghdfe `outcomevar' `ctrls' scl_frac_efmp_pu if dac==1 & aqmd==1, absorb(`absorb1') vce(cluster zip)
		CIs
		estadd local ci = r(se) : withinzip_`outcomevar'_frac
		
	reghdfe `outcomevar' `ctrls' scl_avgsubsidy_efmp_pu if dac==1 & aqmd==1, ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store withinzip_`outcomevar'_avgsub


** broken down by vehicle type 
	local RHSfrac "scl_frac_efmp_puBEV scl_frac_efmp_puPHEV scl_frac_efmp_puHEV"
	local RHSavgsubsidy "scl_avgsubsidy_efmp_puBEV scl_avgsubsidy_efmp_puPHEV scl_avgsubsidy_efmp_puHEV"
	
	
	/*UNMATCHED AND MATCHED OLS DIFF-IN-DIFF ON DAC==1, AVG FUEL ECONOMY*/
	*
	reghdfe `outcomevar' `ctrls' `RHSfrac' if dac==1, ///
		absorb(`absorb1') vce(cluster zip)
		estimates store DinD2_`outcomevar'_frac
	foreach type of local vtypes {
		local coef`type' = 1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )
		estadd scalar MR`type' = `coef`type'' : DinD2_`outcomevar'_frac 
		}
		foreach type of local vtypes {
		*bootstrap the MRs for each type, make new entry in e()
		bootstrap mpg_boot6 = (1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100)), reps(250) seed(123) :reghdfe `outcomevar' `ctrls' `RHSfrac' if dac==1, absorb(`absorb1') vce(cluster zip)
		CIs
		estadd local ci_`type' = r(se) : DinD2_`outcomevar'_frac 
	}
																			
	*
	reghdfe `outcomevar' `ctrls' `RHSfrac' [fw=`outcomeMatch'] if dac==1, ///
		absorb(`absorb1') vce(cluster zip) 
		estimates store DinD2_match_`outcomevar'_frac
	foreach type of local vtypes {
		local coef`type' = 1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )
		estadd scalar MR`type' = `coef`type'' : DinD2_match_`outcomevar'_frac 
		}
	foreach type of local vtypes {	
		*bootstrap the MRs for each type, make new entry in e()
		bootstrap mpg_boot7 = (1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )), reps(250) seed(123) force :reghdfe `outcomevar' `ctrls' `RHSfrac' [fw=`outcomeMatch'] if dac==1, absorb(`absorb1') vce(cluster zip) 
		CIs
		estadd local ci_`type' = r(se) : DinD2_match_`outcomevar'_frac	
	}
	
	
	reghdfe `outcomevar' `ctrls' `RHSavgsubsidy' if dac==1, ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store DinD2_`outcomevar'_avgsub

	reghdfe `outcomevar' `ctrls' `RHSavgsubsidy' [fw=`outcomeMatch'] if dac==1, ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store DinD2_match_`outcomevar'_avgsub


	/*UNMATCHED AND MATCHED OLS TRIPLEDIFF, AVG FUEL ECONOMY*/
	

	reghdfe `outcomevar' `ctrls' `RHSfrac', ///
		absorb(`absorb1') vce(cluster zip)
	estimates store DDD2_`outcomevar'_frac
	foreach type of local vtypes {
		local coef`type' = 1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )
		estadd scalar MR`type' = `coef`type'' : DDD2_`outcomevar'_frac 
		}
	foreach type of local vtypes {	
		*bootstrap the MRs for each type, make new entry in e()
		bootstrap bs_`type' = (1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )), reps(250) seed(123) : reghdfe `outcomevar' `ctrls' `RHSfrac', absorb(`absorb1') vce(cluster zip)
		CIs
		estadd local ci_`type' = r(se) : DDD2_`outcomevar'_frac	
	}
	
	
	reghdfe `outcomevar' `ctrls' `RHSfrac' [fw=`outcomeMatch'], ///
		absorb(`absorb1') vce(cluster zip) 
		estimates store DDD2_match_`outcomevar'_frac
	foreach type of local vtypes {
		local coef`type' = 1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )
		estadd scalar MR`type' = `coef`type'' : DDD2_match_`outcomevar'_frac
		}
	foreach type of local vtypes {
		*bootstrap the MRs for each type, make new entry in e()
		bootstrap bs_`type' = (1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )), reps(250) seed(123) force: reghdfe `outcomevar' `ctrls' `RHSfrac' [fw=`outcomeMatch'], absorb(`absorb1') vce(cluster zip) 
		CIs
		estadd local ci_`type' = r(se) : DDD2_match_`outcomevar'_frac
	}
	
	
	reghdfe `outcomevar' `ctrls' `RHSavgsubsidy', ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store DDD2_`outcomevar'_avgsub

	reghdfe `outcomevar' `ctrls' `RHSavgsubsidy' [fw=`outcomeMatch'], ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store DDD2_match_`outcomevar'_avgsub

		
	
	/*IDENTIFICATION FROM WITHIN ZIP VARIATION IN TREATMENT INTENSITY, DAC == 1, AQMD == 1, AVG FUEL ECONOMY*/
	
	
	reghdfe `outcomevar' `ctrls' `RHSfrac' if dac==1 & aqmd==1, ///
		absorb(`absorb1') vce(cluster zip)
		estimates store withinzip2_`outcomevar'_frac
	foreach type of local vtypes {
		local coef`type' = 1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )
		estadd scalar MR`type' = `coef`type'' : withinzip2_`outcomevar'_frac
		}
	foreach type of local vtypes {
		*bootstrap the MRs for each type, make new entry in e()
		bootstrap bs_`type' = (1/(`gpm`type'' -_b[scl_frac_efmp_pu`type']*100 )), reps(250) seed(123) : reghdfe `outcomevar' `ctrls' `RHSfrac' if dac==1 & aqmd==1, absorb(`absorb1') vce(cluster zip)
		CIs
		estadd local ci_`type' = r(se) : withinzip2_`outcomevar'_frac
	}
	
	
	reghdfe `outcomevar' `ctrls' `RHSavgsubsidy' if dac==1 & aqmd==1, ///
		absorb(`absorb1') vce(cluster zip) 
	estimates store withinzip2_`outcomevar'_avgsub
	
	


/* IV SPECIFICATIONS*/


	local IVlist "IV" 
	
		foreach xvar in scl_frac_efmp_pu scl_avgsubsidy_efmp_pu {
		
			if "`xvar'" == "scl_frac_efmp_pu" local Xstub "frac"
			if "`xvar'" == "scl_avgsubsidy_efmp_pu" local Xstub "avgsub"
			
				
			*Triple Diff IV
			foreach IV in `IVlist'{
			if "`xvar'" == "scl_frac_efmp_pu" local IVvar `IV'_frac_efmp_pu
			if "`xvar'" == "scl_avgsubsidy_efmp_pu" local IVvar `IV'_avgsubsidy_efmp_pu
			
			ivreghdfe `outcomevar' `ctrls' (`xvar' = `IVvar'), ///
				absorb(`absorb1') cluster(zip) savefirst
				mat fstat = e(first)
				estadd scalar fs = fstat[4,1] , replace
				estadd scalar r2= . ,replace
				estimates store DDD_`outcomevar'_`Xstub'_`IV' 
				if "`xvar'" == "scl_frac_efmp_pu" {
					local coef1 = 1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )
					estadd scalar MR = `coef1' : DDD_`outcomevar'_`Xstub'_`IV' 
				bootstrap boot = (1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )), reps(250) seed(123) : ivreghdfe `outcomevar' `ctrls' (`xvar' = `IVvar'), absorb(`absorb1') cluster(zip)  
				CIs
				estadd local ci = r(se) : DDD_`outcomevar'_`Xstub'_`IV' 
				}
				
				
			*Diff in Diff IV
			ivreghdfe `outcomevar' `ctrls' (`xvar' = `IVvar') if dac==1, ///
				absorb(`absorb1') cluster(zip) savefirst
				mat fstat = e(first)
				estadd scalar fs = fstat[4,1] , replace
				estadd scalar r2=.,replace
				estimates store DinD_`outcomevar'_`Xstub'_`IV'
				if "`xvar'" == "scl_frac_efmp_pu" {
					local coef1 = 1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )
					estadd scalar MR = `coef1' : DinD_`outcomevar'_`Xstub'_`IV'
				bootstrap boot = (1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )), reps(250) seed(123) : ivreghdfe `outcomevar' `ctrls' (`xvar' = `IVvar') if dac==1, absorb(`absorb1') cluster(zip)
				CIs
				estadd local ci = r(se) : DinD_`outcomevar'_`Xstub'_`IV' 
				}
				
				
			*Matched Diff in Diff IV
			ivreghdfe `outcomevar' `ctrls' (`xvar' = `IVvar') [fw=`outcomeMatch'] if dac==1, ///
				absorb(`absorb1') cluster(zip) savefirst
				mat fstat = e(first)
				estadd scalar fs = fstat[4,1] , replace
				estadd scalar r2=.,replace
				estimates store DDM_`outcomevar'_`Xstub'_`IV'
				if "`xvar'" == "scl_frac_efmp_pu" {
					local coef1 = 1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )
					estadd scalar MR = `coef1' : DDM_`outcomevar'_`Xstub'_`IV'
				bootstrap boot = (1/(`gpmEFMP' -_b[scl_frac_efmp_pu]*100 )), reps(250) seed(123) force: ivreghdfe `outcomevar' `ctrls' (`xvar' = `IVvar') [fw=`outcomeMatch'] if dac==1, absorb(`absorb1') cluster(zip)
				CIs
				estadd local ci = r(se) : DDM_`outcomevar'_`Xstub'_`IV'
				}
				
				
		}
		
	}
	
	

	

/*TABLES FOR PAPER*/
		
	/*MAIN TABLE - FUEL ECONOMY, TWO PANELS*/		
		
	foreach x in `outcomevar' q {
		foreach xvar in frac avgsub {
			local results_`x'_`xvar' "DinD_`x'_`xvar' DinD_match_`x'_`xvar' DDD_`x'_`xvar' withinzip_`x'_`xvar'"
			local results2_`x'_`xvar' "DinD2_`x'_`xvar' DinD2_match_`x'_`xvar' DDD2_`x'_`xvar' withinzip2_`x'_`xvar'"
		}
	}
	
	
	/*MAIN TABLE - FUEL ECONOMY, TWO PANELS, No IV*/	
	/*Table 2*/
	/*Appendix Tables A.3, A.4 A.5*/	
	local newmtitles2 ""DinD" "Matched DinD" "Triple Diff" "Within Treatment Zip"" 
	
		esttab `results_`outcomevar'_frac' ///
		using "${EFMPFleetDraft}/Tables/${outputSubfolder}/maintable_frac_`outcomevar'_NoIV.tex", ///
		title("Panel A") ///
		replace label se star(* 0.10 ** 0.05 *** 0.01) nogaps nonotes noconstant booktabs ///
		b(a2) se(a2) stats(N r2 MR ci,  labels("Observations" "R-Squared" "Marg. repl. MPG" "MR Bootstrap C.I.")) ///
		mtitles(`newmtitles2') ///
		subs("_" "\_" "Yes" "X" "No" " ")  ///
		fragment

	esttab `results_`outcomevar'_avgsub' ///
		using "${EFMPFleetDraft}/Tables/${outputSubfolder}/maintable_avgsub_`outcomevar'_NoIV.tex", ///
		title("Panel  B") ///
		replace label se star(* 0.10 ** 0.05 *** 0.01) nogaps nonotes noconstant booktabs ///
		b(a2) se(a2) stats(N r2,  labels("Observations" "R-Squared" )) ///
		mtitles(`newmtitles2') ///
		subs("_" "\_" "Yes" "X" "No" " ")  ///
		fragment
		
	/*MAIN TABLE - FUEL ECONOMY, BROKEN DOWN BY VEHICLETYPE, TWO PANELS*/	
		/*Table 3*/
	
		esttab `results2_`outcomevar'_frac' ///
		using "${EFMPFleetDraft}/Tables/${outputSubfolder}/maintable2_frac_`outcomevar'_NoIV.tex", ///
		title("Panel A") ///
		replace label se star(* 0.10 ** 0.05 *** 0.01) nogaps nonotes noconstant booktabs ///
		b(a2) se(a2) stats(N r2 MRBEV ci_BEV MRPHEV ci_PHEV MRHEV ci_HEV ,  labels("Observations" "R-Squared" "MR MPG BEV" "Bootstrap C.I." "MR MPG PHEV" "Bootstrap C.I." "MR MPG HEV" "Bootstrap C.I.")) ///
		mtitles(`newmtitles2') ///
		subs("_" "\_" "Yes" "X" "No" " ")  ///
		fragment

	esttab `results2_`outcomevar'_avgsub' ///
		using "${EFMPFleetDraft}/Tables/${outputSubfolder}/maintable2_avgsub_`outcomevar'_NoIV.tex", ///
		title("Panel  B") ///
		replace label se star(* 0.10 ** 0.05 *** 0.01) nogaps nonotes noconstant booktabs ///
		b(a2) se(a2) stats(N r2,  labels("Observations" "R-Squared" )) ///
		mtitles(`newmtitles2') ///
		subs("_" "\_" "Yes" "X" "No" " ")  ///
		fragment
			
		
		
	/*Appendix Table A.2*/
	
	foreach x in `outcomevar' q {
		foreach xvar in frac avgsub {
			local results_`x'_`xvar' "DinD_`x'_`xvar' DinD_match_`x'_`xvar' DDD_`x'_`xvar' DinD_`x'_`xvar'_IV DDM_`x'_`xvar'_IV DDD_`x'_`xvar'_IV"
		}
	}
	
	local newmtitles ""DinD" "Matched DinD" "Triple Diff" "DinD" "Matched DinD" "Triple Diff""
	
	esttab `results_`outcomevar'_frac' ///
		using "${EFMPFleetDraft}/Tables/${outputSubfolder}/maintable_frac_`outcomevar'.tex", ///
		title("Panel A") ///
		replace label se star(* 0.10 ** 0.05 *** 0.01) nogaps nonotes noconstant booktabs ///
		b(a2) se(a2) stats(N r2 fs MR ci,  labels("Observations" "R-Squared" "F" "Marg. repl. MPG" "MR Bootstrap C.I.")) ///
		mtitles(`newmtitles') ///
		mgroups("OLS" "IV", pattern(1 0 0 1 0 0) span prefix(\multicolumn{@span}{c}{) suffix(})) ///
		subs("_" "\_" "Yes" "X" "No" " ")  ///
		fragment
				

	esttab `results_`outcomevar'_avgsub' ///
		using "${EFMPFleetDraft}/Tables/${outputSubfolder}/maintable_avgsub_`outcomevar'.tex", ///
		title("Panel  B") ///
		replace label se star(* 0.10 ** 0.05 *** 0.01) nogaps nonotes noconstant booktabs ///
		b(a2) se(a2) stats(N r2 fs,  labels("Observations" "R-Squared" "F" )) ///
		mgroups("OLS" "IV", pattern(1 0 0 1 0 0) span prefix(\multicolumn{@span}{c}{) suffix(})) ///
		mtitles(`newmtitles') ///
		subs("_" "\_" "Yes" "X" "No" " ")  ///
		fragment

		
		
		
